package cn.com.darly.videoandroidpm.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import cn.com.darly.videoandroidpm.R;
import cn.com.darly.videoandroidpm.base.BaseFragment;
import cn.com.darly.videoandroidpm.bean.PopInfo;
import cn.com.darly.videoandroidpm.common.ClassCache;
import cn.com.darly.videoandroidpm.ui.adapter.FragmentSettingAdapter;

/**
 * 设置菜单页面
 * @author Darly/张宇辉/2018/5/4 11:53
 * @version 1.0/cn.com.darly.videoandroidpm.ui.fragment
 */
public class SettingFragment extends BaseFragment implements AdapterView.OnItemClickListener {


    private ListView id_fragment_set_lv;

    private FragmentSettingAdapter adapter;

    @Override
    protected int root() {
        return R.layout.fragment_center_setting;
    }

    /*
     * (non-Javadoc)
     *
     * @see com.hellen.base.BaseFragment#initView(android.os.Bundle)
     */
    @Override
    protected void initView(Bundle savedInstanceState) {
        id_fragment_set_lv = rootView.findViewById(R.id.id_fragment_set_lv);
    }

    /*
     * (non-Javadoc)
     *
     * @see com.hellen.base.BaseFragment#loadData()
     */
    @Override
    protected void loadData() {
        adapter = new FragmentSettingAdapter(ClassCache.getFragmentSetting(),R.layout.item_fragment_setting,getActivity());
        id_fragment_set_lv.setAdapter(adapter);
    }

    /*
     * (non-Javadoc)
     *
     * @see com.hellen.base.BaseFragment#initListener()
     */
    @Override
    protected void initListener() {
        id_fragment_set_lv.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        try {
            PopInfo info = (PopInfo) parent.getItemAtPosition(position);
            //已经登录，直接跳转
            Intent intent = new Intent();
            intent.setClass(getActivity(),Class.forName(info.getClazz()));
            startActivity(intent);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
